﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Compilex.BaseLibrary;

namespace Infraestruturex.Automata.SPA
{
    public delegate void SemanticAction();

    [Serializable]
    public class SemanticActionManager
    {
        private SimpleHashtable<string, SemanticAction> semanticActionTable = new SimpleHashtable<string, SemanticAction>();
        public SimpleHashtable<string, SemanticAction> SemanticActionTable
        {
            get { return semanticActionTable; }
            set { semanticActionTable = value; }
        }

        public string AddSemanticAction(SemanticAction action)
        {
            string name = "S" + (semanticActionTable.Count + 1);
            semanticActionTable.Add(name, action);
            return name;
        }

        public SemanticAction this[string name]
        {
            get { return semanticActionTable[name]; }
            set { semanticActionTable[name] = value; }
        }

        public void RunSemanticAction(string semanticActionName)
        {
            if (String.IsNullOrEmpty(semanticActionName))
                return;

            if (semanticActionTable.ContainsKey(semanticActionName))
            {
                semanticActionTable[semanticActionName]();
            }
        }

    }
}
